package com.woniu.zsd.platform.service.impl;

import com.woniu.zsd.platform.dao.ChatMessageMapper;
import com.woniu.zsd.platform.model.ChatMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ChatRecordService {

    @Autowired
    private  ChatMessageMapper chatRecordRepository;

    public  void saveMessage(ChatMessage message) {
        System.out.println("save message"+message);
        ChatMessage record = new ChatMessage();
        record.setSender(message.getSender());
        record.setReceiver(message.getReceiver());
        record.setContent(message.getContent());
        record.setTimestamp(LocalDateTime.now());
        record.setType(message.getType());
        chatRecordRepository.save(record);
    }

    public List<ChatMessage> getChatHistory(String user1, String user2) {
        return chatRecordRepository.findBySenderAndReceiver(user1, user2);
    }
}